import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
  public static void main(String[] args) {
    guessNumberGame();
  }
  
  public static void guessNumberGame() {
    while (true) {
      int shu = cai();
      if (shu == 1) {
        game();
      } else if (shu == 0) {
        System.out.println("游戏结束！");
        break;
      } else {
        System.out.println("输入错误，请重试");
      }
    }
  }
  
  public static int game() {
    Random random = new Random();
    Scanner scanner = new Scanner(System.in);
    int num = random.nextInt(100) + 1;
    for (int i = 0; i < 8; i++) {
      System.out.println("请输入猜测的数字：");
      int sim = scanner.nextInt();
      if (i == 7) {
        if (sim == num) {
          System.out.println("第七次终于猜对了！");
        } else {
          System.out.println("次数用完，游戏结束！");
          System.out.println("正确答案是" + num);
          break;
        }
      }
      if (sim > num) {
        System.out.println("猜大了!");
      } else if (sim < num) {
        System.out.println("猜小了!");
      } else {
        System.out.println("猜对了!");
        System.out.println("你一共猜了" + i + "次！");
        break;
      }
    }
    System.out.println("游戏结束！");
    return num;
  }
  
  public static int cai() {
    System.out.println("-----------------------");
    System.out.println("  1、play      0、exit  ");
    System.out.println("-----------------------");
    System.out.println("请输入数字（1/0）");
    System.out.println("你有七次机会猜数字，超过七次后游戏结束！");
    Scanner scanner = new Scanner(System.in);
    return scanner.nextInt();
  }
}
